package isquirrel.beans;

import static org.junit.Assert.*;
import isquirrel.util.HibernateUtil;
import org.junit.Test;

public class InterestTest {
	
	@Test
	public void testCreatingAnInterest() {
		HibernateUtil.useTestDB();
		
		//insert data
		HibernateUtil.beginTransaction();
		
		Interest i = new Interest("football");
		i.getSubjects().add("dbpedia:Foot_Ball");
		i.getSubjects().add("dbpedia:Soccer");
		
		HibernateUtil.getSession().saveOrUpdate(i);
		
		HibernateUtil.commit();
		
		//fetch data
		HibernateUtil.beginTransaction();
		
		Interest ii = (Interest) HibernateUtil.getSession().load(Interest.class, i.getId());
		assertTrue(ii.getSubjects().contains("dbpedia:Foot_Ball"));
		assertTrue(ii.getSubjects().contains("dbpedia:Soccer"));
		assertFalse(ii.getSubjects().contains("dbpedia:Religion"));
		
		HibernateUtil.commit();
	}
	
	@Test
	public void testEquals() {
		Interest i1 = new Interest("Test");
		Interest i2 = new Interest("Test");
		assertTrue(i1.equals(i2));
	}
}
